package com.example.time_manage_web.controller;

import com.example.time_manage_web.pojo.Todolist;
import com.example.time_manage_web.service.TodoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @BelongsProject: time_manage_web
 * @BelongsPackage: com.example.time_manage_web.controller
 * @Author: fox
 * @CreateTime: 2023-02-14  15:30
 * @Description: TODO
 * @Version: 1.0
 */
@RestController
@RequestMapping("/api")
public class TodoController {

    @Autowired
    private TodoService todoService;

    /*
     * @description 添加信息
     * @author  fox
     * @date    2023/2/15 9:24
     * @param	todolist
     * @return  com.example.time_manage_web.pojo.Todolist
     */
    @PostMapping("/add")
    public int add(Todolist todolist){
        int a= this.todoService.insert(todolist);
        return a;
    }

    /*
     * @description 查询所有
     * @author  fox
     * @date    2023/2/15 9:24
     * @param
     * @return  java.util.List<com.example.time_manage_web.pojo.Todolist>
     */
    @GetMapping("/query")
    public List<Todolist> query(){
        return this.todoService.queryTodolist();
    }

    /*
     * @description 修改
     * @author  fox
     * @date    2023/2/16 19:38
     * @param	todolist
     * @return  影响的数据数量
     */
    @PostMapping("/update")
    public int update(Todolist todolist){
        int a = this.todoService.update(todolist);
        return a;
    }

    /**
     * @description 删除
     * @author  fox
     * @date    2023/2/17 19:00
     * @param	todolist
     * @return  int
     */
    @PostMapping  ("/delete")
    public int delete(Todolist todolist){
        int a = this.todoService.delete(todolist);
        return a;
    }
}
